package com.rybbaby.tss.front.tssPayment.dao.imp;

import com.rybbaby.tss.core.web.dao.imp.GenericDao;
import com.rybbaby.tss.front.tssPayment.dao.ITssPaymentDao;
import com.rybbaby.tss.front.tssPayment.entity.TssPayment;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;

/**
 * @description 缴费表数据库操作实现
 * 
 * @author 雷春琼
 * 
 * @createDate 2017-08-10 上午12:22:55
 */
@Repository
public class TssPaymentDaoImp extends GenericDao<TssPayment> implements ITssPaymentDao {

    @Override
    public List<TssPayment> findDepositById(String id) throws Exception{
        String sql = "select * from tss_payment where stuId = ? AND paymentType = '2' AND depositStatus='1'";
        List<TssPayment> listBySql = this.findListBySql(sql, TssPayment.class, id);
        return listBySql;
    }

    @Override
    public int updateDepositIds(String ids,String memberPackageId,String contractNumber) {
        String sql = "update tss_payment set depositStatus = '2',packageId ='"+memberPackageId+"',contractNumber ='"+contractNumber+"',updateTime=now()  where id in ("+ids+")";
        System.out.println("sql"+sql);
        int j = this.updateBySql(sql);
        return j;
    }

    @Override
    public List<TssPayment> findApplyStatus(String memberId) throws Exception {
        String sql = "select * from tss_payment where stuId = ? AND paymentType in (1,3)";
        List<TssPayment> listBySql = this.findListBySql(sql, TssPayment.class, memberId);
        return listBySql;
    }

    @Override
    public Map<String, Object> findTodayPayment(String adminUserIds) {
        String sql = "select SUM(amount) AS sumAmount from tss_payment where to_days(createTime) = to_days(now()) AND tss_payment.adminUserId in ('"+adminUserIds+"')";
        System.out.println(sql);
        return this.findOneForJdbc(sql,null);
    }

    @Override
    public Map<String, Object> findMonthPayment(String adminUserIds) {
        String sql = "select SUM(amount) AS sumAmount from tss_payment where DATE_FORMAT( createTime, '%Y%m' ) = DATE_FORMAT( CURDATE( ) , '%Y%m' ) AND tss_payment.adminUserId in ('"+adminUserIds+"')";
        System.out.println(sql);
        return this.findOneForJdbc(sql,null);
    }

    @Override
    public Map<String, Object> findContractNumber(String contractNumber) {
        String sql = "select count(id)as size from tss_payment where contractNumber = ?";
        return this.findOneForJdbc(sql,new Object[]{contractNumber});
    }
}
